package com.hdsx.jxcsxm.common;

import com.hdsx.webutil.struts.BaseActionSupport;
import com.opensymphony.xwork2.ActionContext;
import org.apache.struts2.ServletActionContext;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;

/**
 * @author 占贤银
 * time 2024/7/30 14:33
 * description 生命之灯因热情而点燃，生命之舟因拼搏而前行
 */
public abstract class CommonActionSupport extends BaseActionSupport {

    public String getRoleByCookie() {
        try {
            ActionContext context = ActionContext.getContext();
            HttpServletRequest request = (HttpServletRequest) context.get(ServletActionContext.HTTP_REQUEST);
            Cookie[] cookies = request.getCookies();
            if (cookies != null) {
                for (Cookie cookie : cookies) {
                    if ("roleid".equalsIgnoreCase(cookie.getName())) {
                        return cookie.getValue();
                    }
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
            return "";
        }
        return "";
    }
}
